package csc.fresher.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.MailSender;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import csc.fresher.bankservice.BankService;
import csc.fresher.domain.Status;
import csc.fresher.domain.UserInfo;

@Controller
@RequestMapping(value="/changestatus")
public class ChangeStatusController {
	
	@Autowired
	private BankService bankService;
	
	@RequestMapping
	public String goChangeStatus(Model model){
		List<UserInfo> userNew = bankService.usernew();
		List<UserInfo> userActive = bankService.useractive();
		List<UserInfo> userDisable = bankService.userdisable();
		
		model.addAttribute("userNew", userNew);
		model.addAttribute("userActive", userActive);
		model.addAttribute("userDisable", userDisable);
		
		HomeController.page = "changestatus";
		
		return "changestatus";
	}

	@RequestMapping(value="/active/{loginId}")
	public String doActive(Model model, @PathVariable String loginId){
		UserInfo userchange = bankService.getUserInfo(loginId);
		Status stt = bankService.getStatus(2);
		userchange.setStatus(stt);
		bankService.update(userchange);
		
		return "redirect:/changestatus";
	}
	
	@RequestMapping(value="/disable/{loginId}")
	public String doDisable(Model model, @PathVariable String loginId){
		UserInfo userchange = bankService.getUserInfo(loginId);
		Status stt = bankService.getStatus(3);
		userchange.setStatus(stt);
		bankService.update(userchange);
		
		return "redirect:/changestatus";
	}
	
}
